home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / interapplication comm / moreosl / morememory / morememory.c next >
Encoding:
Text File  |  2000-06-23  |  2.6 KB  |  109 lines

  1. /*
  2.     File:        MoreMemory.c
  3.  
  4.     Contains:    Memory utility routines.
  5.  
  6.     Written by:    Quinn
  7.  
  8.     Copyright:    Copyright © 1999 by Apple Computer, Inc., all rights reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.  
  20.          <3>     20/3/00    Quinn   Added MoreBlockCompare.
  21.          <2>      6/3/00    Quinn   Added MoreMemError and temporarily removed SafeHoldMemory from
  22.                                     Carbon builds.
  23.          <1>      1/3/99    Quinn   First checked in.
  24. */
  25.  
  26. /////////////////////////////////////////////////////////////////
  27. // MoreIsBetter Setup
  28.  
  29. #include "MoreSetup.h"
  30.  
  31. /////////////////////////////////////////////////////////////////
  32. // Mac OS Interfaces
  33.  
  34. #include <Traps.h>
  35. #include <Patches.h>
  36. #include <Memory.h>
  37.  
  38. /////////////////////////////////////////////////////////////////
  39. // Our Prototypes
  40.  
  41. #include "MoreMemory.h"
  42.  
  43. /////////////////////////////////////////////////////////////////
  44.  
  45. #if CALL_NOT_IN_CARBON
  46.  
  47. extern pascal OSErr SafeHoldMemory(void *start, ByteCount length)
  48.     // See comment in interface part.
  49. {
  50.     OSErr err;
  51.  
  52.     err = noErr;
  53.  
  54.     if ( GetOSTrapAddress(_HWPriv) != GetToolTrapAddress(_Unimplemented) ) {
  55.         err = HoldMemory(start, length);
  56.     }
  57.     if (err == paramErr) {
  58.         err = noErr;
  59.     }
  60.     
  61.     return err;
  62. }
  63.  
  64. extern pascal OSErr SafeUnholdMemory(void *start, ByteCount length)
  65.     // See comment in interface part.
  66. {
  67.     OSErr err;
  68.     
  69.     err = noErr;
  70.     if ( GetOSTrapAddress(_HWPriv) != GetToolTrapAddress(_Unimplemented) ) {
  71.         err = UnholdMemory(start, length);
  72.     }
  73.     if (err == paramErr) {
  74.         err = noErr;
  75.     }
  76.     return err;
  77. }
  78.  
  79. #endif
  80.  
  81. extern pascal OSErr MoreMemError(void *p)
  82.     // See comment in interface part.
  83. {
  84.     OSErr err;
  85.     
  86.     err = MemError();
  87.     if ((err == noErr) && (p == nil)) {
  88.         MoreAssertQ(false);
  89.         err = memFullErr;
  90.     }
  91.     return err;
  92. }
  93.  
  94. extern pascal Boolean MoreBlockCompare(const void *p1, const void *p2, ByteCount numBytes)
  95.     // See comment in interface part.
  96. {
  97.     const UInt8 *cursor1;
  98.     const UInt8 *cursor2;
  99.  
  100.     cursor1 = p1;    
  101.     cursor2 = p2;
  102.     while (numBytes > 0 && (*cursor1 == *cursor2)) {
  103.         cursor1 += 1;
  104.         cursor2 += 1;
  105.         numBytes -= 1;
  106.     }
  107.     return (numBytes == 0);
  108. }
  109.